<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>getter和setter</title>
  </head>
  <body>
    <script>
      // getter和setter
      class Phone {
        // 对动态属性进行封装
        get price(){
          console.log("价格属性被获取");
          return "100";
        }
        set price(val){
          console.log("价格属性被设置");
        }
      }

      // 实例化对象
      let s = new Phone();
      console.log(s.price);
      s.price = 'free'
    </script>
  </body>
</html>
